package com.ktgj.customer.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ktgj.common.core.annotation.Excel;
import com.ktgj.customer.domain.vo.ImportbenefitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.ImportbenefitMapper;
import com.ktgj.customer.domain.Importbenefit;
import com.ktgj.customer.service.IImportbenefitService;

/**
 * 续费记录
Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-07-27
 */
@Service
public class ImportbenefitServiceImpl implements IImportbenefitService 
{
    @Autowired
    private ImportbenefitMapper importbenefitMapper;

    /**
     * 查询续费记录

     * 
     * @param recordId 续费记录
ID
     * @return 续费记录

     */
    @Override
    public Importbenefit selectImportbenefitById(Long recordId)
    {
        return importbenefitMapper.selectImportbenefitById(recordId);
    }

    /**
     * 查询续费记录
列表
     * 
     * @param importbenefit 续费记录

     * @return 续费记录

     */
    @Override
    public List<Importbenefit> selectImportbenefitList(Importbenefit importbenefit)
    {
        return importbenefitMapper.selectImportbenefitList(importbenefit);
    }

    /**
     * 新增续费记录

     * 
     * @param importbenefit 续费记录

     * @return 结果
     */
    @Override
    public int insertImportbenefit(Importbenefit importbenefit)
    {
        return importbenefitMapper.insertImportbenefit(importbenefit);
    }

    /**
     * 修改续费记录

     * 
     * @param importbenefit 续费记录

     * @return 结果
     */
    @Override
    public int updateImportbenefit(Importbenefit importbenefit)
    {
        return importbenefitMapper.updateImportbenefit(importbenefit);
    }

    /**
     * 批量删除续费记录

     * 
     * @param recordIds 需要删除的续费记录
ID
     * @return 结果
     */
    @Override
    public int deleteImportbenefitByIds(Long[] recordIds)
    {
        return importbenefitMapper.deleteImportbenefitByIds(recordIds);
    }

    /**
     * 删除续费记录
信息
     * 
     * @param recordId 续费记录
ID
     * @return 结果
     */
    @Override
    public int deleteImportbenefitById(Long recordId)
    {
        return importbenefitMapper.deleteImportbenefitById(recordId);
    }

    /**
     * 后端——会员续费记录
     * */
    @Override
    public List<ImportbenefitVo> backSelectImportbenefit(Long customerId) throws Exception {
        if (customerId != null && customerId != 0){
            List<Importbenefit> importbenefits = importbenefitMapper.backSelectImportbenefit(customerId);
            if (importbenefits != null && importbenefits.size() > 0){
                List<ImportbenefitVo> importbenefitVoList = new ArrayList<>();
                for (Importbenefit importbenefit : importbenefits) {
                    ImportbenefitVo importbenefitVo = new ImportbenefitVo();
                    importbenefitVo.setRecordId(importbenefit.getRecordId());
                    importbenefitVo.setCardId(importbenefit.getCardId());
                    importbenefitVo.setNewCardId(importbenefit.getNewguaranteeNo());
                    importbenefitVo.setRenewalTime(importbenefit.getOperadate());
                    importbenefitVo.setCardSoldDept(importbenefit.getCardsolddeptid().toString());
                    importbenefitVo.setCardSoldEmployee(importbenefit.getCardsoldemployeeid().toString());
                    if (importbenefit.getIssyn() == 0){
                        importbenefitVo.setIssyn("false");
                    }
                    else if (importbenefit.getIssyn() == 1){
                        importbenefitVo.setIssyn("true");
                    }
                    importbenefitVo.setExeCuteDate(importbenefit.getExecutedate());
                    importbenefitVoList.add(importbenefitVo);
                }
                return importbenefitVoList;
            }
            else {
                throw new Exception("未查到数据");
            }
        }
        else {
            throw new Exception("缺少必要参数");
        }
    }
}
